package main



import (

"fmt"
"time"
"os"
"strconv"
"os/signal"
"bufio"
)




func saveFile(str string, n int) {
	f, err := os.Create("./output" + strconv.Itoa(n) + ".txt") //创建文件

	if err != nil {
		fmt.Println("os.Create Error:", err.Error())
		return
	}
	defer f.Close()
	w := bufio.NewWriter(f) //创建新的 Writer 对象
	_, errw := w.WriteString(str)
	if errw != nil {
		fmt.Println("WriteString Error:", errw.Error())
		return
	}
	//fmt.Printf("写入 %d 个字节\n", n4)
	w.Flush()
	f.Close()

}


func checkError(err error) {
	if err != nil {
		fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
		os.Exit(1)
	}
}

func end_hook(start int64) {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	s := <-c
	end := time.Now().Unix()
	els_time := end - start
	fmt.Println("Got signal:", s)
	fmt.Println("need time :", els_time)
	os.Exit(1)

}